#ifndef __CHARACTER_CONTROLLER_H__
#define __CHARACTER_CONTROLLER_H__

#include "cocos2d.h"
#include "Box2D/Box2D.h"

using namespace cocos2d;

#define PTM_RATIO 32

class CharacterController
{
protected:
	b2Body * m_body;

	bool isJumping;

	float AirAcc;
	float JumpVelocity;
	float MinJumpVelocity;
	float MinVelocityAirDrag;
	float CoefAirDrag;
	int cmptTouchingGround;

	float maxXVelocity;
	float maxYVelocity;
	float XForce;
	float InvertXForce;
	float XFriction;

	float gravity;


public :

	CharacterController( b2Body * _body )
	{
		m_body = _body;

		isJumping = false;
		AirAcc = 0.0f;
		JumpVelocity = 0.0f;
		MinJumpVelocity = 0.0f;
		MinVelocityAirDrag = 0.0f;
		CoefAirDrag = 0.0f;
		cmptTouchingGround = 0;

		maxXVelocity = 0.0f;
		maxYVelocity = 0.0f;
		XForce = 0.0f;
		InvertXForce = 0.0f;
		XFriction = 0.0f;
		
		gravity = 0.0f;
	}
	virtual ~CharacterController(){};

	virtual void update(ccTime dt) = 0;
	virtual void draw( CCPoint Offset ) {};

	void setXVelocity(float X);
	void setYVelocity(float Y);
	void addXVelocity(float X);
	void addYVelocity(float Y);
    
    b2Body * getBody() {return m_body;}
};

class BasicCharacterController : public CharacterController
{
protected :
	b2Fixture* sensorFootLeft;
	b2Fixture* sensorFootRight;
	b2Fixture* sensorWallLeft;
	b2Fixture* sensorWallRight;

	bool sensorFootLeftIsColliding;
	bool sensorFootRightIsColliding;
	bool sensorWallLeftIsColliding;
	bool sensorWallRightIsColliding;

public :
	BasicCharacterController(  b2Body * _body );
	virtual ~BasicCharacterController();
	virtual void update(ccTime dt);
	virtual void draw( CCPoint Offset);

	bool IsTouchingGround();
	bool IsForcingTouchingWall();
	bool IsTouchingWall();
	void CheckSensor();
};



#endif